using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Petra.Gis.Geometry;
using Petra.Gis.Geometry.Support;
using Petra.Gis.DataServices.WKB.Support;

namespace Petra.Gis.DataServices.WKB
{
  public partial class GeometryFactory
  {
    /***********************************************
     * 28.8.2007
     * 
     * creates LineRing
     * from wkb blob
     * 
     * asida@centrum.cz, initial implementation
     *************************************************/
    private static GeometryBase binaryToLineRing(BinaryReader mBReader/*, int arrayOffset*/, System.Type parentGeomType, WKB.ByteOrder dataEndian)
    {
      //CoordinateList Coords = CoordinateListConverter.ToCoordinateList(((MemoryStream)mBReader.BaseStream).GetBuffer(), arrayOffset, Dimension.dim2D, dataEndian);
      CoordinateList Coords = CoordinateListConverter.ToCoordinateList(mBReader/*, arrayOffset*/, Dimension.dim2D, dataEndian);
      LineRing oGeom = new LineRing();
      oGeom.coordList = Coords;

      return oGeom;
    }





    /***********************************************
     * 28.8.2007
     * 
     * creates blob 
     * from LineRing
     * 
     * asida@centrum.cz, initial implementation
     *************************************************/

    private static byte[] lineRingToBinary(GeometryBase geometry)
    {
      int lBlobSize;

      LineRing _geom = (LineRing)geometry;

      lBlobSize = 4 + (_geom.coordList.Count * 16);

      System.IO.MemoryStream oIMStream = new System.IO.MemoryStream(lBlobSize);
      System.IO.BinaryWriter mBWriter = new System.IO.BinaryWriter(oIMStream);

      oIMStream.Position = 0;

      mBWriter.Write((Int32)_geom.coordList.Count);
      mBWriter.Write(_geom.coordList.ToArray(Dimension.dim2D));

      return oIMStream.ToArray();
    }
  }
}
